﻿using Microsoft.Owin;
using Owin;
using System.Web.Mvc;

using Autofac;
using Autofac.Integration.Owin;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using System.Web.Http;
using System.Reflection;
using System.Web.Routing;

[assembly: OwinStartupAttribute(typeof(AutofacOwinDemo.Startup))]
namespace AutofacOwinDemo
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            //app.Run(context =>
            //{
            //    context.Response.ContentType = "text/plain";
            //    return context.Response.WriteAsync("Hello World!");
            //});

            ConfigureAuth(app);

            var builder = new ContainerBuilder();
            builder.RegisterType<Test1>().As<ITest>();
            builder.RegisterType<Test2>();
            builder.RegisterControllers(typeof(MvcApplication).Assembly);


            var config = new HttpConfiguration();
            WebApiConfig.Register(config);


            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterWebApiFilterProvider(config);

            var container = builder.Build();
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.UseAutofacMvc();

            app.UseAutofacWebApi(config);
            app.UseWebApi(config);


        }
    }
}
